#!/usr/bin/make -f

# Uncomment to enable verbose mode.
#export DH_VERBOSE=1

ANT = /usr/bin/ant
VERSION = $(shell dpkg-parsechangelog | sed -ne 's/^Version: \(.*\)/\1/p')

test:
	dh_testdir
	$(ANT) test

clean:
	dh_testdir
	dh_testroot
	$(ANT) realclean
	rm -f build-stamp build.properties
	rm -rf bin/java
	find -name "*.pyc" -exec rm '{}' ';'
	find -name "*py.class" -exec rm '{}' ';'
	dh_clean

build: build-stamp
build-stamp:
	dh_testdir
	printf "version=%s" $(VERSION) > build.properties

	$(ANT) jar

	touch build-stamp

install: build
	dh_testdir
	dh_testroot
	dh_installdirs
	dh_install

	# Copy in the jar and symlink to something stable
	dh_install build/apache-cassandra-$(VERSION).jar \
		usr/share/cassandra
	dh_install build/apache-cassandra-thrift-$(VERSION).jar \
		usr/share/cassandra
	dh_install build/apache-cassandra-cql-*.jar \
		usr/share/cassandra

	dh_link usr/share/cassandra/apache-cassandra-$(VERSION).jar \
		usr/share/cassandra/apache-cassandra.jar

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installinit -u'start 50 2 3 4 5 . stop 50 0 1 6 .'
	dh_installdocs README.txt CHANGES.txt NEWS.txt
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-dependent files here.
binary-arch: build install
# We have nothing to do by default.

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install
